package com.itheima.controller;

import com.itheima.common.R;
import com.itheima.pojo.Orders;
import com.itheima.pojo.OrdersPage;
import com.itheima.service.OrdersService;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;

/**
 * @author Envy
 */
@RestController
@RequestMapping("/order")
public class OrdersController {
    @Resource
    private OrdersService ordersService;

    /**
     * 提交订单
     */
    @PostMapping("/submit")
    public R<String> submitOrder(@RequestBody Orders orders) throws Exception {
        ordersService.submitOrder(orders);
        return R.success("下单成功");
    }

    /**
     * 订单列表
     */
    @GetMapping("/userPage")
    public R<OrdersPage> ordersList(@RequestParam Integer page,@RequestParam Integer pageSize) {
        page = (page - 1) * pageSize;
        return ordersService.ordersList(page, pageSize);
    }
}
